package com.sca.product.service.impl;

import com.sca.product.dao.ProductDao;
import com.sca.product.entity.Product;
import com.sca.product.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductDao productDao/* = new ProductDao() {
        @Override
        public int create(Product p) {
            return 1;
        }

        @Override
        public Product getProductByid(Long id) {
            return new Product();
        }
    }*/;

    @Override
    public int create(Product product) throws Exception {
        int n = productDao.create(product);
        if(product.getName().equals("99")) {
            throw new Exception("事务回滚");
        }
        return n;
    }

    @Override
    public Product getProductById(Long id) {
        return productDao.getProductByid(id);
    }
}
